import breadcrumb from '@/components/common/breadcrumb'
import fixedbutton from '@/components/common/fixedbutton'
import download from '@/components/common/download'
import {addWin,delFile} from '@/api/api.js'

export default {
    components:{
        breadcrumb,
        fixedbutton,
        download,
    },
    data() {
        return {
            brand:[
                {name:'lang.fun_exp'},
                {name:'cm.add'},
            ],
            showCollapse:"1",
            hasIcon:false,
            fileList:[],
            loading:false,
            fileListDownLoad:[],
            fileUploadUrl:process.env.UPDOWN_ROOT,
            showCollapse1:"1",
            fileProps:[ //文件上传的属性
                {prop:'fileRealName',label:'文件名'},
                {prop:'createTime',label:'上传时间'},
            ],
            win:{
                cudWinLevel:'', //中奖等级
                cudPrizeAmount:'',//奖金额度
                cudWinName:'',//获奖者姓名
                cudPhone:'',//联系方式
                cudWinSpeech:'',//获奖感言
                cudMemo:'',//备注
                cudWinDate:'',//中奖日期
                cudAwardDate:'',//发奖日期
                cudPayType:'',//收款方式
                cudBankCardNo:'',//银行卡号
                cudBonusProperty:[],//奖金性质
            },
        }
    },
    methods: {
        //数据初始化
        initData:function(){

        },
        //取消
        back:function(){
            this.$router.push("/redemp_manage");
        },
        //添加一个流程
        addProc:function(){

            //判断获奖表
            this.$refs['win'].validate((valid)=>{
                if(valid){
                    
                    //设置关联文件
                    this.win.fileList = this.fileListDownLoad;
        
                    let _this = this;
                    this.win.cudBonusProperty = this.win.cudBonusProperty.join(',');
                    //存储数据
                    addWin(this.win).then((result) => {
                        if(result.status == "200" && result.data.code=="0"){
                            _this.$alert("保存成功!",_this.$t('cm.tips'),{
                                callback:_ => {
                                    _this.$router.push("/redemp_manage");
                                }
                            });
                        }else{
                            _this.$alert(result.data.msg,_this.$t('cm.tips'));
                        }
                    }).catch((err) => {
                        _this.$alert(err,_this.$t('cm.tips'));
                    });
                }else{
                    return false;
                }
            })  
        },
        //上传文件时的回调
        upfileBack:function(response, file, fileList){
            this.loading = false;
            if(response.code == "0"){
                this.fileListDownLoad.push(response.data);
            }else{
                this.$alert(response.msg,this.$t('cm.tips'));
            }      
        },
        //上传文件之前的处理
        beforeUpload:function(file){
            //在这里进行上传文件的设置
            let type = file.name.substring(file.name.lastIndexOf('.')+1);
            const limitSize = file.size / 1024 /1024 < 10; //文件大小限制
            if(!limitSize){
                this.$alert("上传文件大小不能超过10M",this.$t('cm.tips'));
            }
            return limitSize;
        },
        //显示 加载中...
        loadingFile:function(){
            this.loading = true;
        },
        //取消显示 加载中...
        uplofileError:function(){
            this.loading = false;
        },
        //删除文件
        delFiles:function(row){
            let _this = this;
            delFile({fileId:row.fileId}).then((result) => {
                if(result.status == "200" && result.data.code == "0"){
                    _this.fileListDownLoad.splice(_this.fileListDownLoad.findIndex(item => item.fileId===row.fileId),1);
                }else{
                    _this.$alert(result.data.msg,_this.$t('cm.tips'));
                }
            }).catch((err) => {
                _this.$alert(err,_this.$t('cm.tips'));
            });
        }
    },
    mounted() {},
    computed: {
        winRules:function(){
            return {
                cudWinLevel:[
                    {required:true,message:this.$t('fe.input_winLevel'),trigger:'change'}
                ],
                cudPrizeAmount:[
                    {required:true,message:this.$t('fe.input_prizeAmount'),trigger:'blur'}
                ],
                cudWinName:[
                    {required:true,message:this.$t('fe.input_winName'),trigger:'blur'}
                ],
                cudPhone:[
                    {required:true,message:this.$t('fe.input_phone'),trigger:'blur'}
                ],
                cudPayType:[
                    {required:true,message:this.$t('fe.input_cudPayType'),trigger:'change'}
                ],
                cudAwardDate:[
                    {required:true,message:this.$t('fe.input_cudAwardDate'),trigger:'change'}
                ],
                cudWinDate:[
                    {required:true,message:this.$t('fe.input_cudWinDate'),trigger:'change'}
                ]
                
            }
        }
    },
}